package com.light.applet.common.entity;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;

/**
 * 用户表(TbUser)表实体类
 *
 * @author weibiao
 * @since 2024-04-18 21:35:05
 */
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
@TableName("tb_account")
public class Account implements UserDetails {
    /**
     * 主键
     */
    @Id
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    //用户昵称
    private String nickName;
    //微信用户唯一标识
    private String openId;
    //头像
    private String avatarUrl;
    //性别
    private Integer gender;
    //简介
    private String description;
    //手机号
    private String mobile;
    //密码
    private String passWord;
    //状态
    private Integer status;
    //用户背景图
    private String coveredImg;
    //城市
    private String city;
    //省份
    private String province;
    //国籍
    private String country;
    //创建时间
    private Date createTime;
    //修改时间
    private Date updateTime;

    @Override
    @JsonIgnore
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return AuthorityUtils.commaSeparatedStringToAuthorityList("admin");
    }

    @Override
    public String getPassword() {
        return this.passWord;
    }

    @Override
    public String getUsername() {
        return this.nickName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

//    @Override
//    public String toString() {
//        return JSON.toJSONString(this);
//    }
}

